'use strict'
let isFH5 = window.FH5JsBridge !== undefined && window.callFH5Handler !== undefined;
let isWx = window.wx !== undefined;

const  callHandler = function(method,options) {
    return new Promise((resolve,reject)=>{
        try {
            if(isFH5) {
                window.callFH5Handler('_one_'+method,options,(res)=> {
                    if(res && (res.status === undefined || res.status === 0)) {
                        resolve(res && res.data || {});
                    } else {
                        reject(new Error(res))
                    }
                })
            } else if(isWx) {
                var func = window.wx[method];
                if(!func && window.wx.miniprogram) {
                    func = window.wx.miniprogram[method];
                }
                var params = Object.assign({success:resolve,fail:reject}, options)
                func && func(params)
            } else {
                reject(new Error('[ONE] can ont find js bridge'));
            }
        } catch(error) {
            reject(error)
        }
    })
}

var defineQueryParams = (url => {
    var result = {};
    var query = url && url.split('?')[1];
    var queryArr = (query && query.split('&')) || [];
    queryArr.forEach(function(item){
        var kv = item.split('=');
        var key = unescape(kv[0]);
        if(key.indexOf('_one_') == 0) {
            var value = unescape(kv[1]);
            result[key] = value;
        }
    })
    return result;
})(location.href)